/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Helpers;

import Hibernate.HibernateUtil;
import Entities.ContentHeader;
import java.util.List;
import org.hibernate.*;

/**
 *
 * @author Erhan
 */
public class ContentHeaderHelper {

    Session session = null;

    /**
     *
     */
    public ContentHeaderHelper() {
        this.session = HibernateUtil.getSessionFactory().getCurrentSession();
    }

    //Ophalen alles
    /**
     *
     * @return
     */
    public List<ContentHeader> getcontentHeader() {
        List<ContentHeader> contentHeaderList = null;
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from Content_Header");
            contentHeaderList = (List<ContentHeader>) q.list();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return contentHeaderList;
    }

    //Ophalen van 1
    /**
     *
     * @param id
     * @return
     */
    public ContentHeader getContentHeader(int id) {
        ContentHeader result = null;
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from Content_Header where id=" + id);
            result = (ContentHeader) q.list().get(0);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }


    // Wegschrijven
    /**
     *
     * @param contentHeader
     */
    public void persistContentHeader(ContentHeader contentHeader) {
        org.hibernate.Transaction tx = session.beginTransaction();
        tx.begin();
        session.persist(contentHeader);
        tx.commit();
    }

    // Verwijderen
    /**
     *
     * @param contentHeader
     */
    public void deleteContentHeader(ContentHeader contentHeader) {
        org.hibernate.Transaction tx = session.beginTransaction();
        tx.begin();
        session.delete(contentHeader);
        tx.commit();
    }

    // Updaten
    /**
     *
     * @param contentHeader
     */
    public void updateContentHeader(ContentHeader contentHeader) {
        org.hibernate.Transaction tx = session.beginTransaction();
        tx.begin();
        session.update(contentHeader);
        tx.commit();
    }
}